class wirtefile:
    def __init__(self):
        self.f =  open('a.txt', 'w', encoding='utf-8')

    def __del__(self):
        self.f.close()

    def writefile(self, content):        
        self.f.write(content)
    def __str__(self):
        print(self.f.closed)   
      

f = wirtefile()
f.writefile('hello')
f.__del__()
f.__str__()